package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DeadMqConfing;
import com.atguigu.gmall.rebbit.service.RabbitService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/mq")
public class MqSendController {

    @Autowired
    private RabbitService rabbitService;

    //发送消息
    @GetMapping("/send")
    public Result sedMessage(String message){
        //交换机 ，路由key 队列名称
        rabbitService.sendMessage("exchange1","routingKey1",message);
        return Result.ok();
    }

    //测试发送
    @GetMapping("/send2")
    public Result sedMessage2(String message){
        //交换机 ，路由key 队列名称
        rabbitService.sendMessage("exchange2","routingKey2",message);
        return Result.ok();
    }

    //死信队列  延迟消息
    @GetMapping("/sendDeadLetter")
    public Result sendDeadLetter(String message){
        rabbitService.sendDeadLetterMapper(DeadLetterMqConfig.exchange_dead+1,DeadLetterMqConfig.routing_dead_1,message,10);
        return Result.ok();
    }

    //基于插件的延迟消息
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        rabbitService.sendDelayMessage(DeadMqConfing.exchange_delay,DeadMqConfing.routing_delay,message,12);
        return Result.ok();
    }
}
